找传奇、传世资源到传世资源站!

c# 一键分班示例源码下载(可按照男女/分数一键分班)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

参考下分班逻辑, 分班后 要求 每个班级 性别均匀,分数均匀

using System;using System.Collections.Generic;using System.Linq;namespace DivideClass{ internal class DivideClass { private readonly IDevideStrategy _devideStrategy; private int count; private int _男女比例因子; public DivideClass(IDevideStrategy devideStrategy, int count, int 男女比例因子 = 5) { _devideStrategy = devideStrategy; this.count = count; this._男女比例因子 = 男女比例因子; } /// <summary> /// 生成测试数据 /// </summary> /// <returns></returns> private IList<Stu> RandomUser() { var list = new List<Stu>(); for (int i = 0; i < count; i ) { var random = new Random(i); int score = random.Next(0, 100); list.Add(new Stu { Score = score, StuNo = i, Sex = (score % _男女比例因子 == 0 ? "女" : "男"), }); } return list; } private Dictionary<int, IList<Stu>> InitClass(int countClass) { var dicDividedUser = new Dictionary<int, IList<Stu>>(); for (int i = 0; i < countClass; i ) { dicDividedUser.Add(i, new List<Stu>()); } return dicDividedUser; } private IList<Stu> GetUser() { return RandomUser(); } public Dictionary<int, IList<Stu>> Divide(int classCount) { IList<Stu> list = GetUser(); IOrderedEnumerable<Stu> 男的 = list.Where(x => x.Sex == "男").OrderByDescending(x => x.Score); IOrderedEnumerable<Stu> 女的 = list.Where(x => x.Sex == "女").OrderByDescending(x => x.Score); Dictionary<int, IList<Stu>> dicDividedUser = InitClass(classCount); _devideStrategy.DevideOnGroup(男的, classCount, dicDividedUser); _devideStrategy.DevideOnGroup(女的, classCount, dicDividedUser); return dicDividedUser; } public void Print(Dictionary<int, IList<Stu>> stuclass) { foreach (var kv in stuclass) { Console.WriteLine("classid=" kv.Key); foreach (Stu stu in kv.Value) { Console.Write(stu.StuNo "=>" stu.Sex "=>" stu.Score "\t"); } Console.WriteLine(); Console.WriteLine("all=>" kv.Value.Count() "=>男" kv.Value.Count(x => x.Sex == "男") "=>女" kv.Value.Count(x => x.Sex == "女") "=>平均分" kv.Value.Average(x => x.Score)); Console.WriteLine(); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复